import axios from '@ohos/axios'
import { promptAction } from '@kit.ArkUI'
import type {anyObject} from '../../models/httpmodel'
const request=axios.create({
  baseURL:"http://192.168.5.56:6060"
})

request.interceptors.request.use((config)=>{
  // 后续添加token信息
  return config
})



request.interceptors.response.use((response)=>{
  if(response.data.code===200){
    return response.data.data
  }else{
    // 错误提示
    promptAction.showToast(response.data.message)
    return Promise.reject(response.data.message)
  }
},(error)=>{
  // 错误提示
  promptAction.showToast(error.message)
  return Promise.reject(error.message)
})


export default  class Http{
  get<T>(url:string,params?:anyObject){
    return request.get<any,T>(url,{params})
  }
  post<T>(url:string,data?:anyObject){
    return request.post<any,T>(url,data)
  }
  put<T>(url:string,data?:anyObject){
    return request.put<any,T>(url,data)
  }
  delete<T>(url:string,params?:anyObject){
    return request.delete<any,T>(url,{params})
  }
}